package com.ch.tools.client.simulator.controller;


import com.ch.ms.dto.MapleCharacterDto;
import com.ch.tools.client.MapleClient;
import com.ch.tools.client.simulator.LoginLauncher;
import com.ch.tools.client.simulator.observable.Observables;
import com.ch.tools.client.simulator.observer.MapleCharactersObserver;
import de.felixroske.jfxsupport.FXMLController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
public class CharacterListViewController implements Initializable {


    private final MapleClient mapleClient;

    @Autowired
    public CharacterListViewController(MapleClient mapleClient) {
        this.mapleClient = mapleClient;
    }


    @Getter
    @FXML
    private TableView<MapleCharacterDto> mapleCharacterPacketTableView;

    @FXML
    private TableColumn<MapleCharacterDto, String> mapleCharacterNameColumn;

    @FXML
    private TableColumn<MapleCharacterDto, Short> mapleCharacterLevelColumn;

    @FXML
    private TableColumn<MapleCharacterDto, Long> mapleCharacterExperienceColumn;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        LoginLauncher.getStage().setTitle("选择角色");
        Observables.getMapleCharactersObservable().addObserver(new MapleCharactersObserver(this));
        mapleCharacterNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        mapleCharacterLevelColumn.setCellValueFactory(new PropertyValueFactory<>("level"));
        mapleCharacterExperienceColumn.setCellValueFactory(new PropertyValueFactory<>("experience"));

    }


}
